home *** CD-ROM | disk | FTP | other *** search
- <!--#INCLUDE FILE="MSGlobal.inc"-->
- <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
- ////////////////////////////////////////////////////////////////////
- // //
- // Fusion ASP Components //
- // Custom JScript Object: MSDBNav //
- // //
- ////////////////////////////////////////////////////////////////////
- /*
- Object: MSDBNav
-
- Version: 1.0 10/02/97
-
- Written By: Application Methods, Inc.
- 6300 Southcenter Blvd.
- Seattle, WA 98188
- (206) 244-2400
- http://www.appmethods.com
-
- Description: This object definition describes properties and methods for a
- dynamically constructed set of navigator buttons. From this object definition,
- the buttons use an existing query comonent on the page to construct links that
- allow the user to navigate to a previous and next record. For the buttons to
- work, the user must define at least one unique column in the query as a key field,
- otherwise, the navigator buttons will not appear. They are also designed so that
- the user will not see a previous button if the user is at the start of the
- recordset, and likewise the next button will not appear at the end of the recordset.
- If the query is defined so that only one record is returned, neither the next or previous
- buttons will appear.
-
-
- Note: Generation of a number of hidden fields is necessary to pass information
- on to other components. All hidden fields created by this object are prefixed
- with 'amASPHidden_' or 'amASPComponent_'. Devlopers should never create
- any form element with these prefixes or unexpected results will occur.
-
- Properties:
- name - Name of navigator component
- queryComponent - Name of query component
- previousImage - Path to previous image
- nextImage - Path to next image
- returnImage - Path to return image
- keyFieldCount - Number of key fields
- keyFieldNames - Key field names
- keyFieldTypes - Key field types
- pageName - Name of page this component resides on
- returnPageName - Name of page to jump to when return button is clicked
- numRecords - Number of records to advance
- detailPage - Whether this is a detail page (single record view)
-
- Methods:
- render - renders all visual elements of component
- createRequestStrings - builds request string
- generateString - builds Navigation advancement string
- emitProperties - emits all object's properties
- getNumRecords - gets number of records to advance
- setDetailArray - gets the values of the keyfields
- createBaseCursor - creates cursor passed to query
- keyFieldMatch - determines existance of fields in query
- findMatch - locates selected record in recordset
-
- Usage: The following example shows a row in a record set being displayed by 4 dynafields
- containing a value from the table "lookup." The usage will script will not work properly unless
- the code for the DataBase Connection and Query Components has been installed is part of your build file.
-
- <HTML>
- <HEAD>
-
- <!SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
-
- // Create and connect the database object
- MSDBConnection1 = new MSDBConnection("test", "ODBC","MS Access", "Northwind","admin","",false);
- MSDBConnection1.connect();
-
- // Create the query object
- MSDBQuery1 = new MSDBQuery("MSDBQuery1", "MSDBConnection1", false, "*", "Customers", "customerID > 7", "lastname");
-
- // Create the dynafield object
- MSDBDynaField1 = new MSDBDynaField( "MSDBDynaField1",
- "true",
- "MSDBQuery1",
- "",
- "ShipCity",
- "string",
- "false",
- 10,
- 10,
- 1,
- "Arial",
- "+0",
- "black",
- "false",
- "false",
- "false");
-
- var keyFields = new Array(1);
- keyFields [1] = "OrderID";
-
- var keyFieldTypes = new Array(1);
- keyFieldTypes [1] = "number";
-
- MSDBNav1 = new MSDBNav("MSDBNav1",
- "MSDBQuery1",
- "prev.jpg",
- "next.jpg",
- "return.jpg",
- 1,
- keyFields,
- keyFieldTypes,
- "test.html",
- "Adhoc.htm",
- 1,
- "true");
-
- <!/SCRIPT>
-
- <META NAME="Generator" CONTENT="NetObjects Fusion 2.0 for Windows">
-
- </HEAD>
- <body>
-
- write("<FORM METHOD=POST>");
- <%
- MSDBConnection1.render()
- MSDBDynaField1.render()
- MSDBNav1.render()
- %>
- write("</FORM>");
-
- </BODY>
- </HTML>
-
- <META NAME="Generator" CONTENT="NetObjects Fusion 2.0.1 for Windows">
-
- <BODY>
- <SERVER>
- write("<FORM METHOD=POST><BR><BR><BR><BR><CENTER>");
- MSDBDynaField1.render();
- MSDBDynaField2.render();
- MSDBDynaField3.render();
- MSDBDynaField4.render();
- write("<BR><BR>");
- MSDBNav1.render();
- write("</FORM></CENTER>");
-
-
- </SERVER>
-
- </BODY>
- </HTML>
-
- =====================================================================*/
-
- //
- // MSDBNav object constructor
- //
- function MSDBNav(name,
- queryComponent,
- previousImage,
- nextImage,
- returnImage,
- keyFieldCount,
- keyFieldNames,
- keyFieldTypes,
- pageName,
- returnPageName,
- numRecords,
- detailPage)
- {
- // Set Properties
- this.name = name;
- this.queryComponent = queryComponent;
- this.previousImage = previousImage;
- this.returnImage = returnImage;
- this.nextImage = nextImage;
- this.pageName = pageName;
- this.returnPageName = returnPageName;
- this.keyFieldCount = (keyFieldCount+"" != "null") ? parseInt(keyFieldCount) : 0;
- this.numRecords = numRecords;
- this.move = "next";
- this.detailPage = detailPage;
- this.validRecord = false;
-
- if (keyFieldNames != null)
- this.keyFieldNames = keyFieldNames;
- else {
- var temp1 = new Array();
- for (var i = 0; i < keyFieldCount; i++)
- temp1[i] = "";
-
- this.keyFieldNames = temp1;
- }
-
- if (keyFieldTypes != null)
- this.keyFieldTypes = keyFieldTypes;
- else {
- var temp1 = new Array();
- for (var i = 0; i < keyFieldCount; i++)
- temp1[i] = "";
-
- this.keyFieldTypes = temp1;
- }
-
- this.detailArray = new Array();
- this.nextRequestString = null;
- this.lastRequestString = null;
- this.returnPageURLString = null;
-
- // Set Methods
- this.render = naRender;
- this.createRequestStrings = naCreateRequestStrings;
- this.generateString = naGenerateString;
- this.emitProperties = naEmitProperties;
- this.getNumRecords = naNumRecords;
- this.setDetailArray = naSetDetailArray;
- this.createBaseCursor = naCreateBaseCursor;
- this.keyFieldMatch = naKeyFieldMatch;
- this.findMatch = naFindMatch;
-
- // Increment global cursor usage counter since this component will try to use the cursor
- incCursorCallCount();
-
- } // END MSDBNav Constructor
-
-
- //
- // Method - naEmitProperties()
- // Emits all the object's properties. Used as a debuging tool to verify correct
- // manipulation of the object.
- //
- function naEmitProperties ()
- {
- write("\n<BR><B>MSDBNavigator Properties:</B>");
- write("\n<BR>name = " + this.name);
- write("\n<BR>queryComponent = " + this.queryComponent);
- write("\n<BR>previousImage = " + this.previousImage);
- write("\n<BR>nextImage = " + this.nextImage);
- write("\n<BR>returnImage = " + this.returnImage);
- write("\n<BR>pageName = " + this.pageName);
- write("\n<BR>returnPageName = " + this.returnPageName);
- write("\n<BR>numRecords = " + this.numRecords);
- write("\n<BR>detailPage = " + this.detailPage);
-
- var i;
- for (i = 0; i < this.keyFieldCount; i++) {
- write("\n<BR>keyFieldNames" + i + " = " + this.keyFieldNames[i]);
- write("\n<BR>keyFieldDataTypes" + i + " = " + this.keyFieldTypes[i]);
- }
- write("<BR>");
- } // END naEmitProperties
-
-
- //
- // Method to output the appropriate HTML to render the object's
- // HTML elements.
- //
- function naRender() {
- // Get the value of the hidden field amlivewireHidden_URLStr.
- // This request object property contains the URL encoded string
- // that is to be appended to the returnPage URL so that the query
- // component on that page can filter on the appropriate field and
- // value. The Prev and Next button URLs need to carry this along
- // so that the property remains in the request object.
- returnPageURLString = eval(this.queryComponent + ".getURLStr()");
-
- addClientStr = "";
-
- // Create request strings for next and previous buttons
- this.createRequestStrings();
-
- // PREVIOUS Button
- // If there is a valid value for the link, show the button
- if (this.lastRequestString != null) {
- addClientStr = this.pageName + "?" + this.lastRequestString;
- if ((returnPageURLString != null) &&
- (returnPageURLString != ""))
- addClientStr += "&amaspHidden_URLStr=" + escape(returnPageURLString);
-
- write("<A HREF=" + addClientStr + ">");
- write("<IMG SRC=\"" + this.previousImage + "\" BORDER=0></A>");
- }
-
- // RETURN (UP) Button
- if (this.returnImage != null) {
- addClientStr = this.returnPageName;
- if ((returnPageURLString != null) &&
- (returnPageURLString != ""))
- addClientStr += "?" + returnPageURLString;
-
- write("<A HREF=" + addClientStr + ">");
- write("<IMG SRC=\"" + this.returnImage + "\" BORDER=0></A>");
- }
-
- // NEXT Button
- // If there is a valid value for the link, show the button
- if (this.nextRequestString != null) {
- addClientStr = this.pageName + "?" + this.nextRequestString;
- if ((returnPageURLString != null) &&
- (returnPageURLString != ""))
- addClientStr += "&amaspHidden_URLStr=" + escape(returnPageURLString);
-
- write("<A HREF=" + addClientStr + ">");
- write("<IMG SRC=\"" + this.nextImage + "\" BORDER=0></A>");
- }
-
- // Decrement global cursor usage counter since this component has tried to use the cursor
- // If the counter has reached zero after doing so, then this is the last cursor using
- // component on the page, so call the DBQuery object's "cursorClose()" method to close
- // the cursor if it's still open.
- decCursorCallCount(this.queryComponent);
-
- } // END naRender
-
- //
- // Method that returns an array that contains the VALUES of the
- // Key Fields in the keyFieldNames array.
- //
- function naSetDetailArray() {
-
- // construct a cursor based on the sql for the Query Component
- getDetailCursor = eval(this.queryComponent + ".getCurrentCursor()");
-
- if (getDetailCursor != null && !eval(this.queryComponent + ".isCursorEnd()")) {
- // Initialize the cursor then create array
- if (!eval(this.queryComponent + ".isCursorInitialized"))
- eval(this.queryComponent + ".initializeCursor()");
-
- var x = 0;
-
- // Fill the detail Array in the same order that the User Created
- // the key fields.
- for (x = 0; x < this.keyFieldCount; x++) {
- if (this.keyFieldTypes[x].toUpperCase() == "DATE")
- this.detailArray[x] = formatDate(getDetailCursor.Fields(this.keyFieldNames[x]));
- else
- this.detailArray[x] = getDetailCursor.Fields(this.keyFieldNames[x]);
- } // end For Loop
- }
- else {
- write("\n<BR>No matching record was found.\n<BR>\n<BR>");
- }
-
- return this.detailArray;
-
- } // END naSetDetailArray
-
- //
- // Method that returns boolean result of matching values in the detailArray
- // with the values of the key fields from the baseCursor's current
- // record.
- //
- function naKeyFieldMatch() {
- match = true;
- // Loop through the keyfields
- for (x = 0; x < this.keyFieldCount; x++) {
- searchCursor = this.baseCursor;
-
- // compare the key field value to the match criteria
- if (this.keyFieldTypes[x].toUpperCase() == "DATE")
- var keyFieldValue = formatDate(searchCursor.Fields(this.keyFieldNames[x]));
- else
- var keyFieldValue = searchCursor.Fields(this.keyFieldNames[x]);
-
- if (keyFieldValue + "" != this.detailArray[x] + "") {
- match = false;
- break;
- } // end if
- } // end for
- return match;
-
- } // END naKeyFieldMatch
-
-
- //
- // Method loops through the baseCursor to find the matching record.
- //
- function naFindMatch() {
- var count = 0;
- found = false;
- while (!found) {
- // call the match function
- if (this.keyFieldMatch())
- {
- found = true;
- // leave loop, a match was found
- break;
- } // end if keyFieldMatch
- ret = (eval(this.queryComponent + ".moveNext(1)"));
- count = count + ret;
-
- if (eval(this.queryComponent + ".isCursorEnd()")) {
- // Cannot Advance Cursor and no match is found -- move to beginning of recordset
- ret = (eval(this.queryComponent + ".movePrevious(" + count + ")"));
- break;
- }
- } // end while (!found)
-
- this.validRecord = found;
-
- } // END naFindMatch
-
-
- //
- // Method that creates the baseCursor based on the query component's
- // SQL properties. (This creates a cursor based on the initial query,
- // not any fields that got passed in.)
- //
- function naCreateBaseCursor() {
- // Create a base cursor only if on a detail page and not already navigating
- if ((!(eval(this.queryComponent + ".isNavigating()"))) && this.detailPage) {
- // Create the array of values to match on
- this.setDetailArray();
-
- // Use the query component's SELECT and FROM clauses as is
- baseSQL = "select " + eval(this.queryComponent + ".select") + " ";
- baseSQL += "from " + eval(this.queryComponent + ".from") + " ";
-
- // Use the query component's WHERE clause if available
- if ((eval(this.queryComponent + ".where") != null) && (eval(this.queryComponent + ".where") != "")) {
- baseSQL += "where (" + eval(this.queryComponent + ".where") + ") ";
- }
-
- // Use the query component's ORDER BY clause is avaialable
- if ((eval(this.queryComponent + ".orderBy") != null) && (eval(this.queryComponent + ".orderBy") != ""))
- baseSQL += "order by " + eval(this.queryComponent + ".orderBy");
-
- // Create the base cursor based using query component's openCursor() method which will also overwrite
- // the query component's old cursor
- this.baseCursor = eval(this.queryComponent + ".openCursor(baseSQL)"); // bug fix, 11/26/97
-
-
- // Locate the initial record
- this.findMatch();
- } // END if ((!(eval(this.queryComponent + ".isNavigating"))) && this.detailPage)
- else {
- this.baseCursor = eval(this.queryComponent + ".getCurrentCursor()");
- eval(this.queryComponent + ".initializeCursor()");
- this.validRecord = true;
- }
-
- } // END naCreateBaseCursor();
-
-
- //
- // Method loops through the query component's cursor to determine which, if either,
- // of the navigation buttons to display.
- //
- function naCreateRequestStrings() {
- this.nextRequestString = null;
- this.lastRequestString = null;
-
- // Create a base cursor when on a detail page and not navigating
- this.createBaseCursor();
-
- // Only show next and/or previous buttons if we're at a valid record in the recordset
- if (this.validRecord) {
- // Advance the recordset this.numRecords + 1 times to check for end of recordset
- var i = 0;
- var ret = 0;
- var count = 0;
-
- ret = (eval(this.queryComponent + ".moveNext(" + (1 + this.numRecords) + ")"));
-
- // If we aren't at the end of the recordset then show next button
- if (parseInt(ret, 10) == parseInt((this.numRecords + 1), 10)) {
- if (parseInt(ret, 10) > this.numRecords)
- this.nextRequestString = this.generateString("next", this.numRecords);
- else
- this.nextRequestString = this.generateString("next", ret);
- }
- else
- this.nextRequestString = null;
-
- // Rewind the recordset to initial position
- ret = (eval(this.queryComponent + ".movePrevious(" + ret + ")"));
-
- // Move to the record two before the initial record to check for beginning of recordset
- ret = (eval(this.queryComponent + ".movePrevious(2)"));
-
- // If we aren't at the beginning of the recordset then show previous button
- if (parseInt(ret, 10) == 2)
- this.lastRequestString = this.generateString("previous", this.numRecords);
- else
- this.lastRequestString = null;
-
- // Move recordset to initial position
- ret = (eval(this.queryComponent + ".moveNext(" + ret + ")"));
- } // end if (this.validRecord)
-
- } // END naCreateRequestStrings
-
-
- //
- // Method that create a request string based on the direction being moved and the number of records
- // by which to navigate.
- //
- function naGenerateString(navDir, navCount) {
- var pre = "amaspHidden_"; // Required so that DBQuery will ignore the property
-
- var requestString = "";
-
- // Add the direction to move to the request string
- requestString = pre + "NavDir=" + navDir;
-
- // Calculate the ordinal position of the recordset for the next page
- if (navDir.toUpperCase() == "NEXT")
- requestString += "&" + pre + "NavPosition=" + (parseInt(eval(this.queryComponent + ".cursorPosition"), 10) + parseInt(navCount, 10));
- else
- requestString += "&" + pre + "NavPosition=" + (parseInt(eval(this.queryComponent + ".cursorPosition"), 10) - parseInt(navCount, 10));
-
- // Add the number of records to navigate to the request string
- requestString += "&" + pre + "NavCount=" + navCount;
-
- // Check for "listActive" flag - if true, append to request string
- // This is necessary to make "Use Previous Query" (see DBQuery) work in conjunction with navigation
- if ( eval(this.queryComponent + ".listActive") )
- requestString += pre + "listActive=true";
-
- return requestString;
- } // END naGenerateString
-
- function naNumRecords() {
- return this.numRecords;
- } // END naNumRecords
-
- </SCRIPT>